struct Light
{
	float4 direction;
	float4 colour;
	float4 ambient;
	float4 position;
	float4 attenuation;
	float2 pad1;
	float range;
	int enabled;
};

//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------
cbuffer ConstantBuffer : register( b0 )
{
	float4 TEST;
	matrix World;
	matrix View;
	matrix Projection;
	matrix LightViewMatrix;
	matrix LightProjMatrix;
	Light light[3];
	float4 OutputColour;
	float2 TexturePositionOne;
	float2 TexturePositionTwo;
	float3 CameraPosition;
}
//--------------------------------------------------------------------------------------
struct VS_INPUT // = PS_INPUT
{
    float4 Pos : POSITION;
    float2 TexCoord : TEXCOORD0;
	float3 Normal : NORMAL0;
	float3 Tangent : TANGENT;
	float3 Binormal : BINORMAL;
};

struct PS_INPUT
{
	float4 Pos : SV_POSITION;
	float2 TexCoord : TEXCOORD0;
	float3 Normal : NORMAL0;
	float3 Tangent : TANGENT;
	float3 Binormal : BINORMAL;
	float4 LightViewPosition : TEXCOORD1;
};


Texture2D ObjTexture : register( t0 );
Texture2D ObjTexture2 : register( t1 );
SamplerState ObjSamplerState : register( s0 );

PS_INPUT VS( VS_INPUT input )
{
    PS_INPUT output = (PS_INPUT)0;

	output.Pos = input.Pos;
	output.TexCoord = input.TexCoord;
	output.Normal = input.Normal;
	
	output.LightViewPosition = mul(input.Pos, World);
	output.LightViewPosition = mul(output.LightViewPosition, LightViewMatrix);
	output.LightViewPosition = mul(output.LightViewPosition, LightProjMatrix);

    return output;
}

float4 PS( PS_INPUT input) : SV_Target
{
	return float4(1.0f, 0.0f, 0.0f, 1.0f);

	float2 projectedTexCoord;
    projectedTexCoord.x = input.LightViewPosition.x / input.LightViewPosition.w / 2.0f + 0.5f;
    projectedTexCoord.y = -input.LightViewPosition.y / input.LightViewPosition.w / 2.0f + 0.5f;

	float4 zBuffer = ObjTexture.Sample(ObjSamplerState, projectedTexCoord);
	float4 lightView = ObjTexture2.Sample(ObjSamplerState, projectedTexCoord);
    float depthValue = zBuffer.r;



	float lightDepthVal = input.LightViewPosition.z / input.LightViewPosition.w;
    float4 outCol = 1;

	if (lightDepthVal > depthValue)
	{
        return float4(0.1f, 0.1f, 0.1f, 1.0f);
    }

	return zBuffer;













    //return input.Pos.z;

	//input.Pos = mul(input.Pos, World);
	//input.Pos *= 0.0001f;
	float4 s1 = ObjTexture.Sample(ObjSamplerState, input.TexCoord);
	float4 s2 = ObjTexture.Sample(ObjSamplerState, input.TexCoord + float2(0.01f, 0.0f));
	s2 += ObjTexture.Sample(ObjSamplerState, input.TexCoord + float2(0.01f, 0.01f));
	s2 += ObjTexture.Sample(ObjSamplerState, input.TexCoord + float2(-0.01f, 0.01f));
	s2 += ObjTexture.Sample(ObjSamplerState, input.TexCoord + float2(0.01f, -0.01f));
	s2 += ObjTexture.Sample(ObjSamplerState, input.TexCoord + float2(-0.01f, -0.01f));
	//s2 = normalize(s2);
	//float4 s3 = ObjTexture.Sample(ObjSamplerState, input.TexCoord + float2(0.2f, 0.0f));
	//float4 s4 = ObjTexture.Sample(ObjSamplerState, input.TexCoord + float2(0.3f, 0.0f));
	float4 finalColour = (s1 + s2) * 0.5f;
	//finalColour.r /= normalize(input.Pos).x;// * 0.5f;
	//finalColour = normalize(finalColour);
	//finalColour.r += normalize(input.Pos.z);
	//finalColour /= (s1 + s2) * 0.5f;;
	//finalColour.rb = 0.5f;
	//finalColour.g *= 2.5f;
	return s1;

	//float4 s1 = ObjTexture.Sample(ObjSamplerState, input.TexCoord);
	//float4 s2 = float4(0.0f, 0.5f, 0.5f, 1.0f);
	////float4 s2 = float4(2.0f, 2.0f, 2.0f, 1.0f);
	////float4 s2 = float4(1.5f, 1.5f, 1.5f, 1.0f);
	//float4 Pos = mul(input.Pos, World);
	////Pos = mul(Pos, View);
	////Pos = mul(Pos, Projection);
	//float4 finalColour = s1;// * s2;
	////finalColour += Pos.z;
	//return finalColour;
}